import { App } from 'vue'
import SvgIcon from '@/lib/components/SvgIcon'

interface Plugin {
  install: any
}

const addSvg: Plugin = {
  install(app: App, needSvg: string[]) {
    app.component('SvgIcon', SvgIcon)

    const req = require.context('./svg', false, /\.svg$/)
    const requireAll = (requireContext: any) => requireContext.keys().filter((key: string) => {
      const name = key.split('.svg')[0].substring(2)
      return needSvg.includes(name)
    }).map(requireContext)
    requireAll(req)
  }
}

export default addSvg
